package util;

import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXServiceURL;
import javax.management.remote.JMXConnectorFactory;
import java.util.Hashtable;
import java.util.Set;

public class ALL_JMX_URLS {

	public static void main(String[] args) throws Exception {

		JMXConnector jmxCon = null;
		try {
			JMXServiceURL serviceUrl = new JMXServiceURL(
					"service:jmx:iiop://127.0.0.1:7001/jndi/weblogic.management.mbeanservers.runtime");
			System.out.println("Connecting to:  " + serviceUrl);
			Hashtable env = new Hashtable();
			env.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,
					"weblogic.management.remote");
			env.put(javax.naming.Context.SECURITY_PRINCIPAL, "weblogic");
			env.put(javax.naming.Context.SECURITY_CREDENTIALS, "weblogic");

			jmxCon = JMXConnectorFactory.newJMXConnector(serviceUrl, env);
			jmxCon.connect();
			MBeanServerConnection con = jmxCon.getMBeanServerConnection();

			Set<ObjectName> mbeans = con.queryNames(null, null);
			for (ObjectName mbeanName : mbeans) {
				System.out.println(mbeanName);
			}
		} finally {
			if (jmxCon != null)
				jmxCon.close();
		}
	}
}
